package org.example.controller;

import org.example.entity.Dataoperationrecordsheet;
import org.example.models.R;
import org.example.service.DataoperationrecordsheetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/dataoperationrecordsheet")
public class DataoperationrecordsheetController {
    @Autowired
    private DataoperationrecordsheetService dataoperationrecordsheetService;

    //通过id查询内容
    @RequestMapping("/getById")
    public R<List<Dataoperationrecordsheet>> getById(@RequestParam("operationTargetId") String operationTargetId){
        List<Dataoperationrecordsheet> byId = dataoperationrecordsheetService.queryAllThroughOperationTargetId(operationTargetId);
        if (byId != null){
            return R.success(byId);
        }
        return R.error("查询失败");
    }
    //添加内容
    @RequestMapping("/insert")
    public R<Dataoperationrecordsheet> insert(@RequestParam("dataoperationrecordsheet") Dataoperationrecordsheet dataoperationrecordsheet){
        boolean save = dataoperationrecordsheetService.save(dataoperationrecordsheet);
        if (save){
            return R.success(dataoperationrecordsheet);
        }
        return R.error("添加失败");
    }
}
